/** \file
* Declarations for the ThreadCall and TypedThreadCall support classes.
* This file is part of Chorus, available at
* http://code.google.com/p/chorus-twitter/ . This file and all associated files
* and derivative works are bound by the terms of the LGPL 3.0 license,
* available at http://www.gnu.org/licenses/lgpl-3.0-standalone.html .
* \par Subversion URL:
* \$URL: http://chorus-twitter.googlecode.com/svn/branches/cpp/src/system/ThreadCall.hpp $
* \version \$Rev: 152 $
* \date    \$Date: 2010-04-06 07:35:13 +0000 (Tue, 06 Apr 2010) $
*/

#pragma once

/// The generic (untyped) abstract thread call class.
class ThreadCall
{
protected:
	ThreadCall() {}
public:
	/// Call the thread callee.
	/// \return True for success.
	virtual bool call() = 0;
};

/// The thread call class. Templated so that the callee instance type can be
/// considered. Callee is the callee instance type.
template <typename Callee>
class TypedThreadCall : public ThreadCall
{
public:
	/// The callee function pointer type.
	typedef bool (Callee::*CalleeFunc)();

public:
	/// The constructor.
	/// \param calleeInit A reference to the callee instance.
	/// \param funcInit   A pointer to the callee member function.
	TypedThreadCall(Callee &calleeInit, CalleeFunc funcInit) :
		callee(calleeInit),
		func(funcInit)
	{}

public:
	/// Call the thread callee.
	/// \return True for success.
	virtual bool call()
	{
		return (callee.*func)();
	}
private:
	/// A reference to the callee instance.
	Callee &callee;
	/// A pointer to the callee member function.
	const CalleeFunc func;
};
